/*
 * > /*
>  * INSANE - Interactive Structural Analysis Environment
>  *
>  * Copyright (C) 2003-2004
>  * Universidade Federal de Minas Gerais
>  * Escola de Engenharia
>  * Departamento de Engenharia de Estruturas
>  *
>  * Author's email :     insane@dees.ufmg.br
>  * Author's Website :   http://www.dees.ufmg.br/insane
>  *
>  * This program is free software; you can redistribute it and/or
>  * modify it under the terms of the GNU General Public License
>  * as published by the Free Software Foundation; either version 2
>  * of the License, or any later version.
>  *
>  * This program is distributed in the hope that it will be useful,
>  * but WITHOUT ANY WARRANTY; without even the implied warranty of
>  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>  * GNU General Public License for more details.
>  *
>  * You should have received a copy of the GNU General Public License
>  * along with this program; if not, write to the Free Software
>  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-
> 1307, USA.
 *
 */

/*
 * Created on 13/06/2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package br.ufmg.dees.insane.xyplot.xyplot_view.dialog;

import java.awt.Toolkit;

import br.ufmg.dees.insane.commons.view.ViewState;
import br.ufmg.dees.insane.xyplot.xyplot_controller.XYPlotController;
import br.ufmg.dees.insane.xyplot.xyplot_view.InterfaceXYPlot;
import br.ufmg.dees.insane.xyplot.xyplot_view.XYPlotView;
import br.ufmg.dees.insane.xyplot.xyplot_view.XYPlotViewState;

/**
 * @author  Samuel Silva Penna  TODO To change the template for this generated type comment go to  Window - Preferences - Java - Code Style - Code Templates
 */
public class SequenceSettingsDialog extends TabbedDialog{
     
    /**
	 * Comment for <code>serialVersionUID</code>
	 */
	private static final long serialVersionUID = 1L;
	private InterfaceXYPlot parent;
    /**
	 * @uml.property  name="seqDialog"
	 * @uml.associationEnd  multiplicity="(0 -1)"
	 */
    public SequenceDialog[] seqDialog;
    private XYPlotViewState state;
    
    /**
     * Constructor method, calling super with the especific title.
     *
     * @param parent The parent of the class.
     * @see xyplot_view.Interface
     */
    public SequenceSettingsDialog(InterfaceXYPlot parent, ViewState s) {
        this.parent = parent;
        state = (XYPlotViewState)s;
        seqDialog = new SequenceDialog[state.getNumberOfSequencesViewStates()];
        for (int i = 0; i < state.getNumberOfSequencesViewStates(); i++){
        	//seqDialog[i] = new SequenceDialog("Sequence",state.getNumberOfSequencesViewStates());
        	seqDialog[i] = new SequenceDialog("Sequence");
            seqDialog[i].getSequenceTitleField().setText(((XYPlotController)parent.getView().getController()).getModel().getSequence(i).getLabel());
            seqDialog[i].setSizeFontSequenceTitle(state.getSequenceState(i).getTitleFontSize());
            seqDialog[i].setTitleColor(state.getSequenceState(i).getTitleColor());
            seqDialog[i].setMarkColor(state.getSequenceState(i).getMarkColor());  
            seqDialog[i].setLineColor(state.getSequenceState(i).getLineColor());
            seqDialog[i].setLineWidth((float)state.getSequenceState(i).getLineWidth());
            seqDialog[i].setMarkFontSize(state.getSequenceState(i).getMarkTextSize());
            if(parent.getModel().getSequence(i).getLabel()!=null){
            	this.addTab(parent.getModel().getSequence(i).getLabel(), seqDialog[i].addSequenceTable(parent.getModel().getSequence(i).getLabel()));
            }else{
            	this.addTab("Sequence "+(i+1), seqDialog[i].addSequenceTable("Sequence "+(i+1)+":"));
            }
            seqDialog[i].getMarkSizeDecimalField().setValue((double)state.getSequenceState(i).getMarkSize());
            seqDialog[i].getTitleFontCombo().setSelectedItem(state.getSequenceState(i).getTitleFont());
            seqDialog[i].getTitleStyleCombo().setSelectedIndex((byte)state.getSequenceState(i).getTitleStyle());
            seqDialog[i].getMarksTypeCombo().setSelectedIndex((int)state.getSequenceState(i).getMarkType());
            seqDialog[i].getLineTypeCombo().setSelectedIndex(state.getSequenceState(i).getLineType());
            
        }
    }
    
    public int showDialog() {
        return super.showDialog(parent, "Sequences Settings");
    }
    
    /**
     * This method is executed on OK button click.
     *
     */
    public void approvedPerform() {
        try {         
            for (int i = 0; i < state.getNumberOfSequencesViewStates(); i++){ 
            	this.seqDialog[i].approvedPerform();
            }
            for (int i = 0; i < state.getNumberOfSequencesViewStates(); i++){
            	 ((XYPlotController)parent.getView().getController()).getModel().getSequence(i).setLabel(seqDialog[i].getSequenceTitleField().getText());
            	 state.getSequenceState(i).setTitleFont((String)seqDialog[i].getTitleFontCombo().getSelectedItem());
            	 state.getSequenceState(i).setTitleFontSize((int)seqDialog[i].getSequenceTitleSizeDecimalField().getValue());
            	 state.getSequenceState(i).setTitleStyle((byte)seqDialog[i].getTitleStyleCombo().getSelectedIndex());
            	 state.getSequenceState(i).setTitleColor(seqDialog[i].getSeqTitleColorField().getBackground());
            	 state.getSequenceState(i).setLineColor(seqDialog[i].getLineColorField().getBackground());
            	 state.getSequenceState(i).setMarkColor(seqDialog[i].getMarksColorField().getBackground());
            	 state.getSequenceState(i).setLineWidth((double)seqDialog[i].getLineWidthDecimalField().getValue());
            	 if(seqDialog[i].getMarksTypeIndex()==10){
            	 	state.getSequenceState(i).setMarksOn(false);             
            	 }else{
            	 	state.getSequenceState(i).setMarksOn(true);                
            	 }
            	 state.getSequenceState(i).setMarkType((byte)seqDialog[i].getMarksTypeIndex()); 
            	 if(seqDialog[i].getTextMarksIndex()==4){
            	 	state.getSequenceState(i).setMarkTextOn(false);
            	 }else{
            	 	state.getSequenceState(i).setMarkTextOn(true);
            	 }  
            	 state.getSequenceState(i).setMarkTextFont(seqDialog[i].getMarksTypeChosen()[seqDialog[i].getTextMarksIndex()]); 
                 state.getSequenceState(i).setMarkTextFont((String)seqDialog[i].getTitleFontCombo().getSelectedItem());
                 state.getSequenceState(i).setMarkTextSize((int)seqDialog[i].getMarkFontSizeDecimalField().getValue());
                 state.getSequenceState(i).setMarkSize((int)seqDialog[i].getMarkSizeDecimalField().getValue());
                 if(seqDialog[i].getLineTypeCombo().getSelectedIndex()==7){
                   	state.getSequenceState(i).setLineOn(false);             
                   }else{
                   	state.getSequenceState(i).setLineOn(true);
                   	state.getSequenceState(i).setDash((int)seqDialog[i].getLineTypeCombo().getSelectedIndex()+1);
                   }
            }
            this.setVisible(false);
            ((XYPlotView)parent.getView()).getDrawingArea().repaint();
          //  LastZoomCommand cmd = new LastZoomCommand(parent);
         //   cmd.execute();
       }catch (Exception err) {
            Toolkit.getDefaultToolkit().beep();
            this.setVisible(false);
       }
    }
    
}
